package com.site.wisdom_construction.controller.iotModule;

import com.site.wisdom_construction.responseEntity.JsonResult;
import com.site.wisdom_construction.responseEntity.OneDataResult;
import com.site.wisdom_construction.responseEntity.Page;
import com.site.wisdom_construction.service.iotModule.LifterMonitorBasicService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author daiyifei
 * @Date 2022/9/1
 * @Description
 */
@Api(tags = "升降机基础数据接口")
@RestController
@RequestMapping("LifterMonitorBasic")
@CrossOrigin
public class LifterMonitorBasicController {
    @Autowired
    private LifterMonitorBasicService lifterMonitorBasicService;
    
    @ApiOperation(value = "增加升降机基础数据", notes = "测试数据:")
    @PostMapping("/insertlifterMonitorBasic")
    public JsonResult insertlifterMonitorBasic(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        int i = lifterMonitorBasicService.insertLifterMonitorBasic(map);
        if (i==1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功录入升降机基础数据!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("录入升降机基础数据失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "删除升降机基础数据", notes = "测试数据:")
    @PostMapping("/deletelifterMonitorBasic")
    public JsonResult deletelifterMonitorBasic(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        List<Integer> list = (List<Integer>) map.get("list");
        int l = 0;
        Map mapR = new HashMap();
        for (int i = 0;i<list.size();i++){
            mapR.put("id",list.get(i));
            int a = lifterMonitorBasicService.deleteLifterMonitorBasic(mapR);
            l+=a;
        }
        if (l>=1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功删除升降机基础数据!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("删除升降机基础数据失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "修改升降机基础数据", notes = "测试数据:")
    @PostMapping("/updatelifterMonitorBasic")
    public JsonResult updatelifterMonitorBasic(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        int i = lifterMonitorBasicService.updateLifterMonitorBasic(map);
        if (i==1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功修改升降机基础数据!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("修改升降机基础数据失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "分页模糊查询升降机基础数据", notes = "测试数据:")
    @PostMapping("/findlifterMonitorBasic")
    public Page findlifterMonitorBasic(@RequestBody Map map) {
        Page page = new Page();
        page.setPageNo((Integer) map.get("pageNo"));
        page.setPageSize((Integer) map.get("pageSize"));
        page.setTotal(lifterMonitorBasicService.Total(map));
        page.setItems(lifterMonitorBasicService.findLifterMonitorBasic(map));
        return page;
    }

    @ApiOperation(value = "分页模糊查询升降机基础数据", notes = "测试数据:")
    @PostMapping("/findLifterMonitorBasicByDeviceId")
    public OneDataResult findLifterMonitorBasicByDeviceId(@RequestBody Map map) {
        OneDataResult oneDataResult = new OneDataResult();
        oneDataResult.setData(lifterMonitorBasicService.findLifterMonitorBasicByDeviceId(map));
        return oneDataResult;
    }


}
